package demo05

/**
 * @author xiaoZhao
 * @date 2022/6/30
 * @describe
 */
object Test06_ConstructorParams {
  def main(args: Array[String]): Unit = {
    val student2 = new Student2("liis", 21)
    println(s"student2: name = ${student2.name}, age = ${student2.age}")

    val student3 = new Student3("wangwu", 90)
//    println(s"student2: name = ${student3.name}, age = ${student3.age}")
    student3.printInfo()

    val student4 = new Student4("haha", 23)
    println(s"student4: name = ${student4.name}, age = ${student4.age}")

    val student5 = new Student5("lala", 98,"清华")
    student5.printInfo()

  }
}

class Student2(var name: String,var age: Int)

//主构造器 无修饰
class Student3( name: String, age: Int){
  def printInfo(): Unit ={
    println(s"student3: name = $name, age = ${age}")
  }
}

class Student4(val name: String,val age: Int)

class Student5(var name: String,var age: Int){
  var school: String = _
  def this( name: String, age: Int,school: String){
    this(name,age)
    this.school = school
  }
  def printInfo(): Unit ={
    println(s"student5: name = $name, age = $age,school = $school")
  }
}